package com.lemon.controller;

import com.lemon.domain.*;
import com.lemon.domain.pageParam.WarehousePageParam;
import com.lemon.domain.vo.WarehousAreaVo;
import com.lemon.domain.vo.WarehouseAreaLocaVo;
import com.lemon.domain.vo.WarehouseVo;
import com.lemon.service.WarehouseAreaLocaService;
import com.lemon.service.WarehouseAreaService;
import com.lemon.service.WarehouseService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/warehouse")
@RequiredArgsConstructor
public class WarehouseController {

    private final WarehouseService warehouseService;
    private final WarehouseAreaService warehouseAreaService;
    private final WarehouseAreaLocaService warehouseAreaLocaService;

    @GetMapping("/list")
    public Result getWarehouseList() {
        List<WarehouseVo> list = warehouseService.getWarehouseList();
        return Result.success(list);
    }
    @GetMapping
    public Result getWarehousePage(WarehousePageParam param) {
        PageResult page = warehouseService.getPage(param);
        return Result.success(page);
    }

    @PostMapping
    public Result addWarehouse(@RequestBody Warehouse warehouse) {
        warehouseService.add(warehouse);
        return Result.success();
    }

    @PutMapping
    public Result updateWarehouse(@RequestBody Warehouse warehouse) {
        warehouseService.updateWarehouse(warehouse);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteWarehouse(@PathVariable Integer id) {
        warehouseService.removeById(id);
        return Result.success();
    }
    @GetMapping("/area/list")
    public Result getWarehouseAreaList(Integer warehouseId) {
        List<WarehousAreaVo> list = warehouseAreaService.getWarehouseAreaList(warehouseId);
        return Result.success(list);
    }

    @GetMapping("/area")
    public Result getWarehouseAreaPage(Integer page, Integer pageSize) {
        PageResult areaPage = warehouseAreaService.getPage(page, pageSize);
        return Result.success(areaPage);
    }

    @PostMapping("/area")
    public Result addWarehouseArea(@RequestBody WarehouseArea warehouseArea) {
        warehouseAreaService.add(warehouseArea);
        return Result.success();
    }

    @PutMapping("/area")
    public Result updateWarehouseArea(@RequestBody WarehouseArea warehouseArea) {
        warehouseAreaService.updateWarehouseArea(warehouseArea);
        return Result.success();
    }

    @DeleteMapping("/area/{id}")
    public Result deleteWarehouseArea(@PathVariable Integer id) {
        warehouseAreaService.removeById(id);
        return Result.success();
    }

    @GetMapping("/loca/list")
    public Result getWarehouseLocaList(Integer warehouseAreaId) {
        List<WarehouseAreaLocaVo> list = warehouseAreaLocaService.getWarehouseLocaList(warehouseAreaId);
        return Result.success(list);
    }

    @GetMapping("/loca")
    public Result getWarehouseLocaPage(Integer page, Integer pageSize) {
        PageResult locaPage = warehouseAreaLocaService.getPage(page, pageSize);
        return Result.success(locaPage);
    }

    @PostMapping("/loca")
    public Result addWarehouseLoca(@RequestBody WarehouseAreaLoca warehouseAreaLoca) {
        warehouseAreaLocaService.add(warehouseAreaLoca);
        return Result.success();
    }

    @PutMapping("/loca")
    public Result updateWarehouseLoca(@RequestBody WarehouseAreaLoca warehouseAreaLoca) {
        warehouseAreaLocaService.updateWarehouseLoca(warehouseAreaLoca);
        return Result.success();
    }

    @DeleteMapping("/loca/{id}")
    public Result deleteWarehouseLoca(@PathVariable Integer id) {
        warehouseAreaLocaService.removeById(id);
        return Result.success();
    }

}
